﻿
var pagesize, pageindex, recordcount, page, url, query, b, s;
recordcount = get("recordcount").value; //记录数
pagesize = get("pagesize").value;     //每页显示条数
pageindex = get("pageindex").value;     //当前页
type = 1;  //类id
var folder = "news";
if (pageindex == 0) {
    pageindex = 1;
}
else {
    pageindex = parseInt(pageindex);
}
page = parseInt((recordcount - 1) / pagesize + 1);  //总页数
url = location.href;
url = url.substring(0, url.indexOf("page"));
if (url == "") {
    url = location.href;
    if (url.indexOf("?") == "-1") {
        url += "?";
    }
    else {
        url += "&";
    }
}
if (recordcount > 0) {
    document.write("<div class='divPG'><a href='/" + folder + "/news-" + type + "-1.html'><div id='pgf' class='divPG1' onmouseover='changebg1(this)' onmouseout='changebg2(this)'>首页</div></a><a href='/" + folder + "/news-" + type + "-" + (pageindex - 1) + ".html'><div id='pgp' class='divPG1'  onmouseover='changebg1(this)' onmouseout='changebg2(this)'>上一页</div></a>");
}
if (pageindex < 7) {
    k = 7 - pageindex;
}
else if (page - pageindex < 7) {
    k = page - 6 - pageindex;
}
else {
    k = 0;
}

for (var i = 1; i <= page; i++) //不足之处，有多少页就循环多少页，有待改进
{
    if (i < 3 || i > (page - 2) || i >= (pageindex + k - 4) && i <= (pageindex + k + 4)) //4为左右2测的页码数1234  5  6789
    {
        document.write("<a href='/" + folder + "/news-" + type + "-" + i + ".html'><div id='pg" + i + "' class='divPG1' onmouseover='changebg1(this)' onmouseout='changebg2(this)'>" + i + "</div></a>");
    }
    if (i == page - 3 && page - pageindex > 6 || i == 3 && pageindex > 7) {
        document.write("<div class='divPG2'>...</div>");
    }
}
if (recordcount > 0) {
    document.write("<a href='/" + folder + "/news-" + type + "-" + (pageindex + 1) + ".html'><div id='pgn' class='divPG1' onmouseover='changebg1(this)' onmouseout='changebg2(this)'>下一页</div></a><a href='/" + folder + "/news-" + type + "-" + page + ".html'><div id='pgl' class='divPG1' onmouseover='changebg1(this)' onmouseout='changebg2(this)'>尾页</div></a></div>")
}

function changebg1(o) {
    o.style.border = "1px solid #2B66A5";
    o.style.background = "#FFFFE0";
}
function changebg2(o) {
    o.style.border = "1px solid #9AAFE5";
    o.style.background = "white";
}
if (pageindex == 1) {
    get("pgf").style.border = "1px solid #929292";
    get("pgf").style.color = "#929292";
    get("pgf").onmouseover = "";
    get("pgf").onmouseout = "";
    get("pgf").parentNode.href = "javascript:";

    get("pgp").style.border = "1px solid #929292";
    get("pgp").style.color = "#929292";
    get("pgp").onmouseover = "";
    get("pgp").onmouseout = "";
    get("pgp").parentNode.href = "javascript:";

}
if (pageindex == page) {
    get("pgn").style.border = "1px solid #929292";
    get("pgn").style.color = "#929292";
    get("pgn").onmouseover = "";
    get("pgn").onmouseout = "";
    get("pgn").parentNode.href = "javascript:";

    get("pgl").style.border = "1px solid #929292";
    get("pgl").style.color = "#929292";
    get("pgl").onmouseover = "";
    get("pgl").onmouseout = "";
    get("pgl").parentNode.href = "javascript:";
}
get("pg" + pageindex).style.border = "1px solid #454444";
get("pg" + pageindex).style.background = "#eeeded";
get("pg" + pageindex).style.color = "#454444";
get("pg" + pageindex).style.fontWeight = "bold";
get("pg" + pageindex).onmouseover = "";
get("pg" + pageindex).onmouseout = "";
get("pg" + pageindex).parentNode.href = "javascript:";


function get(id) {
    return (id.constructor == String) ? document.getElementById(id) : id;
}